package com.nori6.ui;

import com.nori6.R;
import com.nori6.controller.LoginController;
import com.nori6.controller.NoriController;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
 
public class LoginActivity extends NoriActivity 
{
    private EditText _email;
    private EditText _password;
	@Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        // setting default screen to login.xml
        setContentView(R.layout.login);
 
        TextView registerScreen = (TextView) findViewById(R.id.link_to_register);
 
        // Listening to register new account link
        registerScreen.setOnClickListener(new View.OnClickListener() {
 
            public void onClick(View v) {
                // Switching to Register screen
                Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
                startActivity(i);
            }
        });
        
        TextView loginButton = (TextView) findViewById(R.id.btnLogin);
        
        loginButton.setOnClickListener(new View.OnClickListener() 
        {
        	 
            public void onClick(View v) 
            {
            	_email = (EditText)findViewById(R.id.reg_email);
            	_password = (EditText)findViewById(R.id.reg_password);
            	
            	Boolean success = ((LoginController)_controller).HandleLogin(_email.toString(), _password.toString());
            	
            	if(success)
            	{
	            	// Switching to Entrance screen
	                Intent i = new Intent(getApplicationContext(), EntranceActivity.class);
	                startActivity(i);
            	}
            }
        });
    }

	@Override
	protected NoriController createController() 
	{
		return new LoginController(this);
	}
}